package com.open.demo.apm

/**
 *
 */
object SysUtils {

    const val TIME_MILLIS_TO_NANO = 1000000
    const val DEFAULT_EVIL_METHOD_THRESHOLD_MS = 700

    /**
     * 获取某个进程的CPU使用率
     */
    fun getProcessPriority(pid:Int) {
    }

    /**
     * 计算出CPU使用率
     */
    fun calculateCpuUsage(threadMs: Long, ms: Long):String {
        if (threadMs <= 0) {
            return if (ms > 1000) "0%" else "100%"
        }
        return if (threadMs >= ms) {
            "100%"
        } else String.format("%.2f", 1f * threadMs / ms * 100) + "%"
    }

}